package com.youth.youthservice.controller;

import com.youth.commonutils.JwtUtils;
import com.youth.commonutils.R;
import com.youth.commonutils.UserDto;
import com.youth.youthservice.client.MemberClient;
import com.youth.youthservice.entity.EduComment;
import com.youth.youthservice.entity.vo.CourseVo.SearchObject4Comment;
import com.youth.youthservice.service.EduCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author：SBX
 * @Package：com.youth.youthservice.controller
 * @Project：youth-college
 * @name：EduCommentController
 * @Date：2023/6/5 21:36
 * @Filename：EduCommentController
 */
@RestController
@RequestMapping("/eduservice/comment")
public class EduCommentController {

    @Autowired
    private EduCommentService commentService;


    @ApiOperation(value = "评论分页列表")
    @GetMapping("{page}/{limit}")
    public R pageList(@ApiParam(name = "page", value = "当前页码", required = true)
                      @PathVariable Long page,
                      @ApiParam(name = "limit", value = "每页记录数", required = true)
                      @PathVariable Long limit,
                      @ApiParam(name = "courseQuery", value = "查询对象", required = false) String courseId) {
        return commentService.pageList(page, limit, courseId);
    }

    @ApiOperation(value = "添加评论")
    @PostMapping("auth/save")
    public R save(@RequestBody EduComment comment, HttpServletRequest request) {
        return commentService.comment(comment, request);
    }

    @ApiOperation(value = "后台分页查询评论")
    @PostMapping("{page}/{limit}")
    public R pageList4BackEnd(@ApiParam(name = "page", value = "当前页码", required = true)
                              @PathVariable Long page,
                              @ApiParam(name = "limit", value = "每页记录数", required = true)
                              @PathVariable Long limit,
                              @ApiParam(name = "courseQuery", value = "查询对象", required = false)
                              @RequestBody SearchObject4Comment searchObject) {
        return commentService.pageList4BackEnd(page, limit, searchObject);
    }

    @ApiOperation(value = "删除评论")
    @DeleteMapping("{id}")
    public R deleteComment(@PathVariable("id") String id) {
        boolean remove = commentService.removeById(id);
        return remove ? R.ok() : R.error();
    }

}
